--[[
	GMod Last Man Standing, a gamemode for Garry's Mod
    Copyright (C) 2012 Wickex

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
]]

local plym = FindMetaTable("Player")
if not plym then return end

function plym:IsSurvivalist() return self:Team() == TEAM_SURVIVALIST end
function plym:IsSpec() return self:Team() == TEAM_SPEC end

function plym:Hunger()
	return self.Hunger
end
if GetConVar("glms_debug"):GetBool() then concommand.Add("hunger", function(ply, cmd, args) print(ply:Hunger())) end

function plym:SetHunger(amount)
	self.Hunger = amount
end

function plym:GiveHunger(amount)
	self.Hunger = self.Hunger + amount
end

function plym:HungerUpdate()
	if not IsValid(self) then return end
	
	if not self.Hunger <= 0 then 
		self.Hunger = self.Hunger - 1
	end
	
	if self.Hunger <= 0 then
		self:SetHealth(self:Health() - 1)
		self:SetWalkSpeed(150)
		self:SetRunSpeed(150)
		if self:Health() <= 0 then
			self:Kill()
		end
	end
end